package View;

import Bussiness.Delete_Action;
import Bussiness.Insert_Action;
import Bussiness.Search_Action;
import Bussiness.TableModel;
import Bussiness.Update_Action;
import Model.MonHoc;

import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import java.awt.Toolkit;
import java.awt.SystemColor;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * 
 * @author Nhóm java lớp PNV2T - Nguyễn Thị Lệ Đài - Nguyễn Chí Hướng
 * 
 */
public class QuanLyMonHoc extends javax.swing.JFrame {

	private Vector vecHeader = null;
	private Vector vecMonHoc = null;
	private MonHoc monChon = null;

	/** Creates new form QuanLySinhVien */
	public QuanLyMonHoc() {
		try {
			UIManager
					.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (UnsupportedLookAndFeelException ex) {
			ex.printStackTrace();
		} catch (IllegalAccessException ex) {
			ex.printStackTrace();
		} catch (InstantiationException ex) {
			ex.printStackTrace();
		} catch (ClassNotFoundException ex) {
			ex.printStackTrace();
		}
		initComponents();
		setLocation(520, 30);
		showMonHoc();
	}

	/**
	 * Set table of subject and show on table
	 */
	public void showMonHoc() {
		Search_Action sa = new Search_Action();
		// Return a subject object
		vecMonHoc = sa.DanhSachMonHoc();

		vecHeader = new Vector();
		vecHeader.add("Tên Môn");
		vecHeader.add("Khóa Học");
		vecHeader.add("Năm Học");
		vecHeader.add("Số Tín Chỉ");

		// Set table model
		TableModel absModel = new TableModel(vecMonHoc, vecHeader,
				TableModel.Type_DanhSachMonHoc);
		tbl_DanhSachMon.setModel(absModel);
		tbl_DanhSachMon.setRowHeight(30);
		// Close action
		sa.Close();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed"
	// desc=" Generated Code ">//GEN-BEGIN:initComponents
	private void initComponents() {
		ThemMonHoc = new javax.swing.JDialog();
		ThemMonHoc.getContentPane().setBackground(SystemColor.activeCaption);
		ThemMonHoc.setBackground(SystemColor.activeCaption);
		ThemMonHoc.setIconImage(Toolkit.getDefaultToolkit().getImage(
				QuanLyMonHoc.class.getResource("/Icon/QLSV.jpg")));
		jPanel3 = new javax.swing.JPanel();
		jToolBar1 = new javax.swing.JToolBar();
		jLabel2 = new javax.swing.JLabel();
		btn_CapNhap = new javax.swing.JButton();
		jSeparator1 = new javax.swing.JSeparator();
		jLabel4 = new javax.swing.JLabel();
		jLabel5 = new javax.swing.JLabel();
		jLabel6 = new javax.swing.JLabel();
		jLabel7 = new javax.swing.JLabel();
		txt_TenMon = new javax.swing.JTextField();
		Spner_KyHoc = new javax.swing.JSpinner();
		Spner_NamHoc = new javax.swing.JSpinner();
		Spner_SoTinChi = new javax.swing.JSpinner();
		SuaMonHoc = new javax.swing.JDialog();
		SuaMonHoc.getContentPane().setBackground(SystemColor.activeCaption);
		SuaMonHoc.setBackground(SystemColor.activeCaption);
		jPanel4 = new javax.swing.JPanel();
		jToolBar2 = new javax.swing.JToolBar();
		jLabel3 = new javax.swing.JLabel();
		btn_CapNhapSua = new javax.swing.JButton();
		jLabel8 = new javax.swing.JLabel();
		jSeparator2 = new javax.swing.JSeparator();
		jLabel9 = new javax.swing.JLabel();
		jLabel10 = new javax.swing.JLabel();
		jLabel11 = new javax.swing.JLabel();
		jLabel12 = new javax.swing.JLabel();
		txt_TenMonSua = new javax.swing.JTextField();
		Spner_KyHocSua = new javax.swing.JSpinner();
		Spner_NamHocSua = new javax.swing.JSpinner();
		Spner_SoTinChiSua = new javax.swing.JSpinner();
		jPanel2 = new javax.swing.JPanel();
		jLabel14 = new javax.swing.JLabel();
		jToolBar6 = new javax.swing.JToolBar();
		btn_Them = new javax.swing.JButton();
		jLabel15 = new javax.swing.JLabel();
		btn_Sua = new javax.swing.JButton();
		jLabel16 = new javax.swing.JLabel();
		btn_Xoa = new javax.swing.JButton();
		jScrollPane4 = new javax.swing.JScrollPane();
		tbl_DanhSachMon = new javax.swing.JTable();

		ThemMonHoc.setTitle("Thêm môn học ...");
		jPanel3.setBackground(SystemColor.activeCaption);
		jToolBar1.setBackground(SystemColor.inactiveCaption);
		jToolBar1.setFloatable(false);
		jLabel2.setForeground(new java.awt.Color(227, 239, 249));
		jLabel2.setText("    ");
		jToolBar1.add(jLabel2);

		btn_CapNhap.setBackground(new java.awt.Color(227, 239, 249));
		btn_CapNhap.setFont(new java.awt.Font("Times New Roman", 1, 13));
		btn_CapNhap.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/Icon/Sua.png")));
		btn_CapNhap.setText("Cập Nhật");
		btn_CapNhap.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btn_CapNhapActionPerformed(evt);
			}
		});

		jToolBar1.add(btn_CapNhap);

		jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel4.setText("Tên môn : ");

		jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel5.setText("Khóa học : ");

		jLabel6.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel6.setText("Năm học : ");

		jLabel7.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel7.setText("Số tín chỉ : ");

		txt_TenMon.setFont(new java.awt.Font("Times New Roman", 0, 13));
		txt_TenMon.setBorder(javax.swing.BorderFactory
				.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

		Spner_KyHoc.setFont(new java.awt.Font("Times New Roman", 0, 13));

		Spner_NamHoc.setFont(new java.awt.Font("Times New Roman", 0, 13));

		Spner_SoTinChi.setFont(new java.awt.Font("Times New Roman", 0, 13));

		javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(
				jPanel3);
		jPanel3.setLayout(jPanel3Layout);
		jPanel3Layout
				.setHorizontalGroup(jPanel3Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel3Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel3Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel7)
														.addComponent(jLabel6)
														.addComponent(jLabel5)
														.addComponent(jLabel4))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel3Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																Spner_KyHoc,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																68,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																Spner_NamHoc,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																68,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																Spner_SoTinChi,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																68,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																txt_TenMon,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																296,
																Short.MAX_VALUE))
										.addContainerGap())
						.addComponent(jSeparator1,
								javax.swing.GroupLayout.DEFAULT_SIZE, 385,
								Short.MAX_VALUE)
						.addComponent(jToolBar1,
								javax.swing.GroupLayout.DEFAULT_SIZE, 385,
								Short.MAX_VALUE));
		jPanel3Layout
				.setVerticalGroup(jPanel3Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel3Layout
										.createSequentialGroup()
										.addComponent(
												jToolBar1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												38,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(8, 8, 8)
										.addComponent(
												jSeparator1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(19, 19, 19)
										.addGroup(
												jPanel3Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel4)
														.addComponent(
																txt_TenMon,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																24,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel3Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel5)
														.addComponent(
																Spner_KyHoc,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																22,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(8, 8, 8)
										.addGroup(
												jPanel3Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel6)
														.addComponent(
																Spner_NamHoc,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																22,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel3Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel7)
														.addComponent(
																Spner_SoTinChi,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																22,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));

		javax.swing.GroupLayout ThemMonHocLayout = new javax.swing.GroupLayout(
				ThemMonHoc.getContentPane());
		ThemMonHoc.getContentPane().setLayout(ThemMonHocLayout);
		ThemMonHocLayout.setHorizontalGroup(ThemMonHocLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
						javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
		ThemMonHocLayout.setVerticalGroup(ThemMonHocLayout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
				javax.swing.GroupLayout.DEFAULT_SIZE,
				javax.swing.GroupLayout.PREFERRED_SIZE));
		SuaMonHoc.setTitle("Sửa th\u00f4ng tin môn học ...");
		jPanel4.setBackground(new java.awt.Color(227, 239, 249));
		jToolBar2.setBackground(new java.awt.Color(227, 239, 249));
		jToolBar2.setFloatable(false);
		jLabel3.setForeground(new java.awt.Color(227, 239, 249));
		jLabel3.setText(".....");
		jToolBar2.add(jLabel3);

		btn_CapNhapSua.setBackground(new java.awt.Color(227, 239, 249));
		btn_CapNhapSua.setFont(new java.awt.Font("Times New Roman", 1, 13));
		btn_CapNhapSua.setIcon(new javax.swing.ImageIcon(getClass()
				.getResource("/Icon/Sua.png")));
		btn_CapNhapSua.setText("Cập Nhật");
		btn_CapNhapSua.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btn_CapNhapSuaActionPerformed(evt);
			}
		});

		jToolBar2.add(btn_CapNhapSua);

		jLabel9.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel9.setText("Tên môn : ");

		jLabel10.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel10.setText("Khóa học : ");

		jLabel11.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel11.setText("Năm học : ");

		jLabel12.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel12.setText("Số tín chỉ : ");

		txt_TenMonSua.setFont(new java.awt.Font("Times New Roman", 0, 13));
		txt_TenMonSua.setBorder(javax.swing.BorderFactory
				.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

		Spner_KyHocSua.setFont(new java.awt.Font("Times New Roman", 0, 13));

		Spner_NamHocSua.setFont(new java.awt.Font("Times New Roman", 0, 13));

		Spner_SoTinChiSua.setFont(new java.awt.Font("Times New Roman", 0, 13));

		javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(
				jPanel4);
		jPanel4.setLayout(jPanel4Layout);
		jPanel4Layout
				.setHorizontalGroup(jPanel4Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel4Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel4Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel12)
														.addComponent(jLabel11)
														.addComponent(jLabel10)
														.addComponent(jLabel9))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel4Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																Spner_KyHocSua,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																68,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																Spner_NamHocSua,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																68,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																Spner_SoTinChiSua,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																68,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																txt_TenMonSua,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																297,
																Short.MAX_VALUE))
										.addContainerGap())
						.addComponent(jSeparator2,
								javax.swing.GroupLayout.DEFAULT_SIZE, 386,
								Short.MAX_VALUE)
						.addComponent(jToolBar2,
								javax.swing.GroupLayout.DEFAULT_SIZE, 386,
								Short.MAX_VALUE));
		jPanel4Layout
				.setVerticalGroup(jPanel4Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel4Layout
										.createSequentialGroup()
										.addComponent(
												jToolBar2,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												38,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(8, 8, 8)
										.addComponent(
												jSeparator2,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(19, 19, 19)
										.addGroup(
												jPanel4Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel9)
														.addComponent(
																txt_TenMonSua,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																24,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel4Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel10)
														.addComponent(
																Spner_KyHocSua,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																22,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(8, 8, 8)
										.addGroup(
												jPanel4Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel11)
														.addComponent(
																Spner_NamHocSua,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																22,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel4Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel12)
														.addComponent(
																Spner_SoTinChiSua,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																22,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));

		javax.swing.GroupLayout SuaMonHocLayout = new javax.swing.GroupLayout(
				SuaMonHoc.getContentPane());
		SuaMonHoc.getContentPane().setLayout(SuaMonHocLayout);
		SuaMonHocLayout.setHorizontalGroup(SuaMonHocLayout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE,
				javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
		SuaMonHocLayout.setVerticalGroup(SuaMonHocLayout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE,
				javax.swing.GroupLayout.DEFAULT_SIZE,
				javax.swing.GroupLayout.PREFERRED_SIZE));

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("Danh sách môn học ...");
		setResizable(false);
		jPanel2.setBackground(new java.awt.Color(227, 239, 249));
		jLabel14.setFont(new java.awt.Font("Times New Roman", 1, 20));
		jLabel14.setForeground(new java.awt.Color(204, 0, 204));
		jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel14.setText("Danh sách môn học");

		jToolBar6.setBorder(null);
		jToolBar6.setFloatable(false);
		jToolBar6.setOpaque(false);
		btn_Them.setFont(new java.awt.Font("Times New Roman", 1, 13));
		btn_Them.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/Icon/Them.png")));
		btn_Them.setText("Thêm");
		btn_Them.setOpaque(false);
		btn_Them.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btn_ThemActionPerformed(evt);
			}
		});

		jToolBar6.add(btn_Them);

		jLabel15.setFont(new java.awt.Font("Times New Roman", 1, 14));
		jLabel15.setForeground(new java.awt.Color(187, 183, 183));
		jLabel15.setText(" | ");
		jToolBar6.add(jLabel15);

		btn_Sua.setFont(new java.awt.Font("Times New Roman", 1, 13));
		btn_Sua.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/Icon/edit_22.png")));
		btn_Sua.setText("Sửa");
		btn_Sua.setOpaque(false);
		btn_Sua.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btn_SuaActionPerformed(evt);
			}
		});

		jToolBar6.add(btn_Sua);

		jLabel16.setFont(new java.awt.Font("Times New Roman", 1, 14));
		jLabel16.setForeground(new java.awt.Color(187, 183, 183));
		jLabel16.setText(" | ");
		jToolBar6.add(jLabel16);

		btn_Xoa.setFont(new java.awt.Font("Times New Roman", 1, 13));
		btn_Xoa.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/Icon/Xoa_22.png")));
		btn_Xoa.setText("Xóa");
		btn_Xoa.setOpaque(false);
		btn_Xoa.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btn_XoaActionPerformed(evt);
			}
		});

		jToolBar6.add(btn_Xoa);


		tbl_DanhSachMon.setFont(new java.awt.Font("Times New Roman", 0, 13));

		tbl_DanhSachMon.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] {}, new String[] { "Tên Môn", "Khóa Học",
						"Năm Học", "Số Tín Chỉ" }) {
			Class[] types = new Class[] { java.lang.String.class,
					java.lang.Integer.class, java.lang.Integer.class,
					java.lang.Integer.class };
			boolean[] canEdit = new boolean[] { false, false, false, false };

			public Class getColumnClass(int columnIndex) {
				return types[columnIndex];
			}

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
		tbl_DanhSachMon.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				tbl_DanhSachMonMouseClicked(evt);
			}
		});

		jScrollPane4.setViewportView(tbl_DanhSachMon);

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
				jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout
				.setHorizontalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addGap(10, 10, 10)
										.addComponent(
												jToolBar6,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												516, Short.MAX_VALUE)
										.addContainerGap())
						.addComponent(jLabel14,
								javax.swing.GroupLayout.DEFAULT_SIZE, 536,
								Short.MAX_VALUE)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(
												jScrollPane4,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												516, Short.MAX_VALUE)
										.addContainerGap()));
		jPanel2Layout
				.setVerticalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addComponent(
												jLabel14,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												40,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jToolBar6,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												32,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jScrollPane4,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												346, Short.MAX_VALUE)
										.addContainerGap()));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
				javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
				javax.swing.GroupLayout.DEFAULT_SIZE,
				javax.swing.GroupLayout.PREFERRED_SIZE));

		// Window to be sized to fit the preferred size
		pack();
	}// </editor-fold>//GEN-END:initComponents

	/**
	 * Delete subject
	 * 
	 * @param evt
	 */
	private void btn_XoaActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btn_XoaActionPerformed
		if (tbl_DanhSachMon.getSelectedRowCount() == 0) {
			JOptionPane.showMessageDialog(null,
					"Bạn hãy chọn môn học muốn xóa !", "Select Null!",
					JOptionPane.ERROR_MESSAGE);
		} else {
			int row = tbl_DanhSachMon.getSelectedRow();
			monChon = (MonHoc) vecMonHoc.get(row);

			// Declare class to search the subject want to delete if is exist
			// and class to delete subject
			Search_Action sa = new Search_Action();
			Delete_Action da = new Delete_Action();

			/*
			 * Check if the subject is exist
			 */
			if (sa.KiemTraMon(monChon.getID()) == true) {
				int j = JOptionPane.showConfirmDialog(null,
						"Bạn có muốn xóa tất cả Kết quả học tập của môn "
								+ monChon.getTenMon() + " không ?",
						"Delete ... !", 2);
				// Agree to delete studying result of subject
				if (j == 0) {
					// Delete "BangDiemMonHoc" object
					if (da.XoaBangDiemMonHoc(monChon.getID()) == true) {
						// Delete "MonHoc" object
						if (da.XoaMonHoc(monChon.getID()) == true) {
							JOptionPane.showMessageDialog(this,
									"Xóa thành công", "Delete", 2);
							// Load "MonHoc" table
							showMonHoc();
						} else {
							JOptionPane.showMessageDialog(this,
									"Không xóa môn học", "Delete", 2);
						}
					} else {
						JOptionPane.showMessageDialog(null,
								"Không xóa tất cả bảng môn !", "Error !",
								JOptionPane.ERROR_MESSAGE);
					}
				}
			} else {
				/*
				 * Result of subject is not exist Delete the subject do not need
				 * to delete studying result
				 */

				int j = JOptionPane.showConfirmDialog(null,
						"Bạn có muốn xóa môn học này không ?", "Delete ... !",
						2);
				if (j == 0) {
					if (da.XoaMonHoc(monChon.getID()) == true) {
						JOptionPane.showMessageDialog(this, "Xóa thành công",
								"Delete", 2);
						// Show the result by loading table after delete
						showMonHoc();
					} else {
						JOptionPane.showMessageDialog(this,
								"Không xóa được môn học", "Delete", 2);
					}
				}
			}
			// Close action
			da.Close();
			sa.Close();
		}
	}// GEN-LAST:event_btn_XoaActionPerformed

	/**
	 * Update subject
	 * 
	 * @param evt
	 */
	private void btn_CapNhapSuaActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btn_CapNhapSuaActionPerformed
		String TenMon = txt_TenMonSua.getText();
		int KyHoc = Integer.parseInt(String.valueOf(Spner_KyHocSua.getValue()));
		int NamHoc = Integer
				.parseInt(String.valueOf(Spner_NamHocSua.getValue()));
		int SoTinChi = Integer.parseInt(String.valueOf(Spner_SoTinChiSua
				.getValue()));

		// Check data input
		if (TenMon.equalsIgnoreCase("")) {
			JOptionPane.showMessageDialog(null, "Bạn chưa nhập tên môn !",
					"Error !", JOptionPane.ERROR_MESSAGE);

			// Requests that this Component gets the input focus
			txt_TenMon.requestFocus();
		} else {
			monChon.setTenMon(TenMon);
			monChon.setKyHoc(KyHoc);
			monChon.setNamHoc(NamHoc);
			monChon.setSoTinChi(SoTinChi);

			Update_Action ua = new Update_Action();
			if (ua.SuaMonHoc(monChon) == true) {
				int j = JOptionPane.showConfirmDialog(null,
						"Sửa thành công ! Bạn có sửa tiếp ?", "Continue ... !",
						2);
				if (j != 0) {
					showMonHoc();
					SuaMonHoc.dispose();
				}
			} else {
				JOptionPane.showMessageDialog(this, "Không sửa được !");
			}

			ua.Close();
		}
	}// GEN-LAST:event_btn_CapNhapSuaActionPerformed

	/**
	 * Add new subject
	 * 
	 * @param evt
	 * 
	 */
	private void btn_CapNhapActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btn_CapNhapActionPerformed
		String TenMon = txt_TenMon.getText();
		int KyHoc = Integer.parseInt(String.valueOf(Spner_KyHoc.getValue()));
		int NamHoc = Integer.parseInt(String.valueOf(Spner_NamHoc.getValue()));
		int SoTinChi = Integer.parseInt(String.valueOf(Spner_SoTinChi
				.getValue()));

		if (TenMon.equalsIgnoreCase("")) {
			JOptionPane.showMessageDialog(null, "Bạn chưa nhập tên môn !",
					"Error !", JOptionPane.ERROR_MESSAGE);
			txt_TenMon.requestFocus();
		} else {
			MonHoc mon = new MonHoc();
			mon.setTenMon(TenMon);
			mon.setKyHoc(KyHoc);
			mon.setNamHoc(NamHoc);
			mon.setSoTinChi(SoTinChi);

			Insert_Action ia = new Insert_Action();
			if (ia.ThemMonHoc(mon) == true) {
				int j = JOptionPane.showConfirmDialog(null,
						"Thêm thành công ! Bạn có muốn thêm tiếp không ?",
						"Continue ... !", 2);
				if (j != 0) {
					showMonHoc();
					ThemMonHoc.dispose();
				} else {
					txt_TenMon.setText("");
					Spner_KyHoc.setValue(0);
					Spner_NamHoc.setValue(0);
					Spner_SoTinChi.setValue(0);
				}
			} else {
				JOptionPane.showMessageDialog(this, "Không thêm được !");
			}

			// Close action
			ia.Close();
		}
	}// GEN-LAST:event_btn_CapNhapActionPerformed

	/**
	 * Listener of click on list subject table
	 * 
	 * @param evt
	 */
	private void tbl_DanhSachMonMouseClicked(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_tbl_DanhSachMonMouseClicked
		if (evt.getClickCount() == 2) {
			int row = tbl_DanhSachMon.getSelectedRow();
			monChon = (MonHoc) vecMonHoc.get(row);
			SuaMonHoc.setVisible(true);
			SuaMonHoc.pack();
			SuaMonHoc.setLocation(520, 30);
			

			txt_TenMonSua.setText(monChon.getTenMon());
			Spner_KyHocSua.setValue(monChon.getKyHoc());
			Spner_NamHocSua.setValue(monChon.getNamHoc());
			Spner_SoTinChiSua.setValue(monChon.getSoTinChi());
		}
	}// GEN-LAST:event_tbl_DanhSachMonMouseClicked


	/**
	 * Update subject
	 * 
	 * @param evt
	 */
	private void btn_SuaActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btn_SuaActionPerformed
		if (tbl_DanhSachMon.getSelectedRowCount() == 0) {
			JOptionPane.showMessageDialog(null,
					"Bạn hãy chọn môn học muốn sửa !", "Select Null !",
					JOptionPane.ERROR_MESSAGE);
		} else {
			int row = tbl_DanhSachMon.getSelectedRow();
			monChon = (MonHoc) vecMonHoc.get(row);
			SuaMonHoc.setVisible(true);
			SuaMonHoc.pack();
			SuaMonHoc.setLocation(520, 30);

			txt_TenMonSua.setText(monChon.getTenMon());
			Spner_KyHocSua.setValue(monChon.getKyHoc());
			Spner_NamHocSua.setValue(monChon.getNamHoc());
			Spner_SoTinChiSua.setValue(monChon.getSoTinChi());
		}
	}// GEN-LAST:event_btn_SuaActionPerformed

	/**
	 * Open dialog to add new subject
	 * 
	 * @param evt
	 */
	private void btn_ThemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btn_ThemActionPerformed
		ThemMonHoc.setVisible(true);
		ThemMonHoc.pack();
		ThemMonHoc.setLocation(520, 20);
	}// GEN-LAST:event_btn_ThemActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JSpinner Spner_KyHoc;
	private javax.swing.JSpinner Spner_KyHocSua;
	private javax.swing.JSpinner Spner_NamHoc;
	private javax.swing.JSpinner Spner_NamHocSua;
	private javax.swing.JSpinner Spner_SoTinChi;
	private javax.swing.JSpinner Spner_SoTinChiSua;
	private javax.swing.JDialog SuaMonHoc;
	private javax.swing.JDialog ThemMonHoc;
	private javax.swing.JButton btn_CapNhap;
	private javax.swing.JButton btn_CapNhapSua;
	private javax.swing.JButton btn_Sua;
	private javax.swing.JButton btn_Them;
	private javax.swing.JButton btn_Xoa;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel10;
	private javax.swing.JLabel jLabel11;
	private javax.swing.JLabel jLabel12;
	private javax.swing.JLabel jLabel14;
	private javax.swing.JLabel jLabel15;
	private javax.swing.JLabel jLabel16;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JLabel jLabel7;
	private javax.swing.JLabel jLabel8;
	private javax.swing.JLabel jLabel9;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JPanel jPanel3;
	private javax.swing.JPanel jPanel4;
	private javax.swing.JScrollPane jScrollPane4;
	private javax.swing.JSeparator jSeparator1;
	private javax.swing.JSeparator jSeparator2;
	private javax.swing.JToolBar jToolBar1;
	private javax.swing.JToolBar jToolBar2;
	private javax.swing.JToolBar jToolBar6;
	private javax.swing.JTable tbl_DanhSachMon;
	private javax.swing.JTextField txt_TenMon;
	private javax.swing.JTextField txt_TenMonSua;
	// End of variables declaration//GEN-END:variables

}
